import static pulpcore.image.Colors.*;
import pulpcore.Input;
import pulpcore.Stage;
import pulpcore.image.CoreGraphics;
import pulpcore.scene.Scene2D;
import pulpcore.sound.Sound;
import pulpcore.sprite.FilledSprite;
import pulpcore.image.CoreImage;
import pulpcore.math.Path;
import pulpcore.sprite.ImageSprite;
import pulpcore.sprite.ScrollPane;
import pulpcore.sprite.Sprite;
public class marioWorld extends Scene2D{
private mario player;
private goomba evil;
private mushroom grow;
private ScrollPane background;
private ImageSprite world;
private double position;

	
	@Override
	public void load()
	{
		world = new ImageSprite(CoreImage.load("world1-3.png"),0,-500,5000,1000);
		player = new mario(150,275);
	    evil = new goomba(200,200);
	    grow = new mushroom(250, 300);
	    background = new ScrollPane(0,0,500,500,1,1);
	    background.add(world);
	    background.setScrollUnitSize(5);
		add(background);
	    //add((evil));
	    //add((grow));
		add((player));
	    Sound themeSong = Sound.load("Fall-02.wav");
	    themeSong.play();
	}

	@Override
	public void drawScene(CoreGraphics graphics)
	{
		getMainLayer().draw(graphics);
		graphics.setColor(BLACK);
		graphics.drawRect(0, 0, Stage.getWidth(), Stage.getHeight());
	}

	@Override
	public void update(int elapsedTime)
	{
		updatePlayer();
		updateGoomba();
		updateMushroom();

	}
	
	private void updatePlayer() {
		if(Input.isDown(Input.KEY_RIGHT)) {

			//player.runRight();
			background.scrollRight();

			if(Input.isPressed(Input.KEY_SPACE)) {
				player.starter();
				player.jump();
			}
			//player.setThrust(true);
		}else if(Input.isDown(Input.KEY_LEFT)) {
			//player.runLeft();
			if(Input.isPressed(Input.KEY_SPACE)) {
				player.starter();
				player.jump();
			}
			//player.setThrust(true); 
		}else if(Input.isPressed(Input.KEY_SPACE)) {
			player.starter();
			player.jump();
		//player.setThrust(true);
		}else {
			player.setThrust(false);
		}
	}
	private void updateGoomba() {
		if(player.isThrust() == false) {
		/*	if(evil.getViewX() > 0 && evil.isRunningRight() == false) {
				evil.runLeft();
				evil.starter();
			}else if(evil.getViewX() > 0 && evil.isRunningRight() == true) {
				evil.runLeft();
				evil.starter();
			}else{
				evil.runLeft();
			}
			*/
			if(evil.getViewX() < 0){
				evil.runRight();
			}else if(evil.getViewX() > 400){
				evil.runLeft();
			}else{
				if(evil.isRunningRight() == true){
					evil.runRight();
				}else{
					evil.runLeft();
				}
			}
		} else if(Input.isDown(Input.KEY_DOWN)) {
			evil.runLeft();
			evil.starter();
		} else {
			evil.setThrust(false);
		}
	}

	private void updateMushroom() {
		if(player.isThrust() == false) {
			if(grow.getViewX() < 0) {
				grow.runRight();
			} else if(grow.getViewX() > 400){
				grow.runLeft();
			}else{
				if(grow.isRunningRight() == true){
					grow.runRight();
				} else{
					grow.runLeft();
				}
			}
		} else if(Input.isDown(Input.KEY_DOWN)) {
			grow.runLeft();
			grow.starter();
		} else {
			grow.setThrust(false);
		}
	}
}


